using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VFX;

public class BuffIgnited:BuffBase {

	public override string spriteName => "ignited";

	VisualEffect vfx;
	float timeAfterTick;

	public BuffIgnited(BuffSlot slot,Mob mob) : base(slot,mob) { }

	int tickNumber;

	protected override void Update() {
		base.Update();
		timeAfterTick+=Time.deltaTime;
		if(!vfx) vfx=ParticleManager.Create("CharacterFire",mob.position).GetComponent<VisualEffect>();
		vfx.transform.position=mob.spriteRenderer.bounds.min+Vector3.down*0.01f;
		vfx.SetFloat("Intensity",stacks);
		vfx.SetVector2("Size",mob.spriteRenderer.bounds.size);

		if(timeAfterTick>0.25f) {
			timeAfterTick-=0.25f;
			DamageStats damage = new DamageStats();
			damage.amount=3f+1.25f*stacks;
			damage.damageElement=DamageElement.Fire;
			damage.damageType=DamageType.OverTime;
			damage.isComposition=true;
			damage.createParticles=false;
			mob.Damage(damage);

			tickNumber++;
			if(tickNumber%5==0) {
				foreach(var i in Mob.instances) {
					if((i.position-mob.position).sqrMagnitude>4) continue;
					if(i.buffs[typeof(BuffIgnited)].stacks>=stacks) continue;
					i.buffs[typeof(BuffIgnited)].stacks+=0.4f+0.1f*stacks;
				}
				tickNumber=0;
			}

			stacks-=0.15f+0.05f*stacks;
			if(stacks<=0) RemoveSelf();
		}

	}

	protected override void OnRemove() {
		base.OnRemove();
		vfx?.gameObject.SetActive(false);
	}

}
